package com.community.backend.controller;

import com.community.backend.pojo.ShareFee;
import com.community.backend.pojo.dto.ShareFeeQueryDTO;
import com.community.backend.service.ShareFeeService;
import com.community.backend.utils.PageResult;
import com.community.backend.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/*
物业费
 */
@Slf4j
@RestController
@RequestMapping("/shareFee")
public class ShareFeeController {
    private final ShareFeeService shareFeeService;

    public ShareFeeController(ShareFeeService shareFeeService) {
        this.shareFeeService = shareFeeService;
    }

    @GetMapping("/page")
    public Result<PageResult> page(ShareFeeQueryDTO shareFeeQueryDTO) {
        log.info("公摊费分页信息：{}", shareFeeQueryDTO);
        PageResult pageResult = shareFeeService.pageQuery(shareFeeQueryDTO);
        return Result.success(pageResult);
    }
    /**
     * 催款
     * @param id
     * @return
     */
    @GetMapping("/publish/{id}")
    public Result PublishShareFee(@PathVariable String id) {
        shareFeeService.selectById(id);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result shareFeeDetail(@PathVariable String id) {
        ShareFee shareFee = shareFeeService.shareFeeDetail(id);
        return Result.success(shareFee);
    }
    @PostMapping
    public Result save(@RequestBody ShareFee shareFee) {
        shareFeeService.save(shareFee);
        return Result.success("添加成功");
    }
    @PutMapping
    public Result Update(@RequestBody ShareFee shareFee) {
        shareFeeService.update(shareFee);
        return Result.success();
    }
    @DeleteMapping("/{id}")
    public Result DeleteById(@PathVariable String id) {
        shareFeeService.deleteById(id);
        return Result.success("删除成功");
    }

}
